define(["jquery", "easy-admin"], function ($, ea) {

    var init = {
        table_elem: '#currentTable',
        table_render_id: 'currentTableRenderId',
        index_url: 'system.gen/index',
        add_url: 'system.gen/add',
        edit_url: 'system.gen/edit',
        delete_url: 'system.gen/delete',
        export_url: 'system.gen/export',
        modify_url: 'system.gen/modify',
        import_url: 'system.gen/import',
        import_save_url: 'system.gen/importSave',
        preview_url: 'system.gen/preview',
        gen_url: 'system.gen/gen',
    };

    var Controller = {

        index: function () {
            ea.table.render({
                init: init,
                cols: [[
                    {type: 'checkbox'},
                    {field: 'id', title: 'ID'},
                    {field: 'table_name', title: '表名称'},
                    {field: 'table_comment', title: '表描述', edit: 'text'},
                    {field: 'class_name', title: '实体类名称'},
                    {field: 'create_time', title: '创建时间', search: 'range' },
                    {field: 'update_time', title: '更新时间', search: 'range' },
                    {width: 250, title: '操作', templet: ea.table.tool , fixed:'right', operat: [
                            [{
                                text: '预览',
                                url: init.preview_url,
                                method: 'open',
                                auth: 'preview',
                                class: 'layui-btn layui-btn-xs layui-btn-normal',
                            }], 'edit', 'delete', [{
                                text: '生成',
                                title: '确定要生成吗？',
                                url: init.gen_url,
                                method: 'request',
                                auth: 'gen',
                                class: 'layui-btn layui-btn-xs layui-btn-normal',
                            }]]},

                ]],
                toolbar: ['refresh',
                    [{
                        text: '导入',
                        url: init.import_url,
                        method: 'open',
                        auth: 'import',
                        class: 'layui-btn layui-btn-warm layui-btn-sm',
                        icon: 'fa fa-download ',
                        extend: 'data-full="true"',
                    }],
                    'delete', 'export'],
            });

            ea.listen();
        },
        add: function () {
            ea.listen();
        },
        edit: function () {
            ea.listen();
        },
        import: function () {
            let _init = init;
            _init.index_url = init.import_url;
            ea.table.render({
                init: _init,
                cols: [[
                    //{type: 'checkbox'},
                    //{field: 'id', title: 'ID'},
                    {field: 'table_name', title: '表名称'},
                    {field: 'table_comment', title: '表描述'},
                    {field: 'create_time', title: '创建时间', search: 'range' },
                    {field: 'update_time', title: '更新时间', search: 'range' },
                    {width: 250, title: '操作', templet: ea.table.tool, fixed:'right', operat: [
                            [{
                                text: '导入',
                                url: init.import_save_url,
                                method: 'request',
                                auth: 'importSave',
                                field: 'table_name',
                                class: 'layui-btn layui-btn-xs layui-btn-normal',
                            }]],
                    },
                ]],
                toolbar: ['refresh'],

            });

            ea.listen();
        },
    };
    return Controller;
});